package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsPolicyLaw;
import com.ruoyi.system.domain.news.query.NewsPolicyLawQuery;
import com.ruoyi.system.domain.news.vo.NewsPolicyLawVo;
import com.ruoyi.system.service.news.NewsPolicyLawService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsPolicyLaw")
@Api(value = "newsPolicyLawApiController", tags  = "政策标准Api")
public class NewsPolicyLawApiController extends BaseController {

	@Resource
	private NewsPolicyLawService newsPolicyLawService;

	@ApiOperation(value = "获取单个政策标准信息", notes = "获取单个政策标准信息")
	@GetMapping("/getById")
	public R<NewsPolicyLaw> getById(@RequestParam(value = "id") Long id) {
		NewsPolicyLawQuery newsPolicyLawQuery = new NewsPolicyLawQuery();
		newsPolicyLawQuery.setId(id);
		List<NewsPolicyLawVo> newsPolicyLawList = newsPolicyLawService.getNewsPolicyLawList(newsPolicyLawQuery);
		if (newsPolicyLawList!=null&&newsPolicyLawList.size()>0) {
			return R.ok(newsPolicyLawList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取政策标准信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsPolicyLawVo>> list(@RequestBody NewsPolicyLawQuery newsPolicyLawQuery) {
        newsPolicyLawQuery.setIsEnable("1");
		List<NewsPolicyLawVo> newsPolicyLawList = newsPolicyLawService.getNewsPolicyLawList(newsPolicyLawQuery);
		return R.ok(new PageInfo<>(newsPolicyLawList));
	}
}
